Inside Macintosh: QuickTime

Previous | Chapter Top | Chapter Contents | Next

Working With Media Samples

The Movie Toolbox provides a number of functions that allow applications to determine information about a movie's sample data. This section discusses these functions. Refer to "Adding Samples to Media Structures," for information about functions that allow you to retrieve sample data from a media.

Your application can use the GetMovieDataSize , GetTrackDataSize , and GetMediaDataSize functions to determine the size, in bytes, of the data stored in a media, movie, or track.

You can use the GetMediaSampleDescriptionCount and GetMediaSampleDescription functions to retrieve a media's sample descriptions. The SetMediaSampleDescription function enables you to change the contents of a particular sample description associated with a media. The GetMediaSampleCount function determines the number of samples in a media. The SampleNumToMediaTime and MediaTimeToSampleNum functions allow you to convert from a time value to a sample number and vice versa. You can use the functions described in "Finding Interesting Times," to locate specific samples in a media.

GetMovieDataSize

The GetMovieDataSize function allows your application to determine the size, in bytes, of the sample data in a segment of a movie.

pascal long GetMovieDataSize (Movie theMovie, TimeValue startTime,
                                         TimeValue duration);
theMovie
Specifies the movie for this operation. You obtain this movie identifier from such functions as NewMovie , NewMovieFromFile , and NewMovieFromHandle (described on NewMovie , NewMovieFromFile , and NewMovieFromHandle , respectively).
startTime
Contains a time value specifying the starting point of the segment.
duration
Contains a time value that specifies the duration of the segment.

DESCRIPTION

The GetMovieDataSize function returns a long integer that contains the size, in bytes, of the movie's sample data that lies in the specified segment. GetMovieDataSize counts each use of a sample. That is, if a movie uses a given sample more than once, the size of that sample is included in the returned size value one time for each use. Consequently, the returned size is greater than or equal to the actual size of the movie's sample data, and corresponds to the amount of movie data that will be retrieved when you call the FlattenMovie function or FlattenMovieData function (described on FlattenMovie and FlattenMovieData , respectively).

ERROR CODES

invalidMovie

-2010

This movie is corrupted or invalid

invalidDuration

-2014

This duration value is invalid

invalidTime

-2015

This time value is invalid

GetTrackDataSize

The GetTrackDataSize function allows your application to determine the size, in bytes, of the sample data in a segment of a track.

pascal long GetTrackDataSize (Track theTrack, TimeValue startTime,
                                         TimeValue duration);
theTrack
Specifies the track for this operation. You obtain this track identifier from such Movie Toolbox functions as NewMovieTrack and GetMovieTrack (described on NewMovieTrack and GetMovieTrack , respectively).
startTime
Contains a time value specifying the starting point of the segment.
duration
Contains a time value that specifies the duration of the segment.

DESCRIPTION

The GetTrackDataSize function returns a long integer that contains the size, in bytes, of the track's sample data that lies in the specified segment.

This function counts each use of a sample. That is, if a track uses a given sample more than once, the size of that sample is included in the returned size value one time for each use. Consequently, the returned size is greater than or equal to the actual size of the track's sample data.

ERROR CODES

invalidTrack

-2009

This track is corrupted or invalid

invalidDuration

-2014

This duration value is invalid

invalidTime

-2015

This time value is invalid

GetMediaDataSize

The GetMediaDataSize function allows your application to determine the size, in bytes, of the sample data in a media segment.

pascal long GetMediaDataSize (Media theMedia, TimeValue startTime,
                                         TimeValue duration);
theMedia
Specifies the media for this operation. Your application obtains this media identifier from such Movie Toolbox functions as NewTrackMedia and GetTrackMedia (described on NewTrackMedia and GetTrackMedia , respectively).
startTime
Contains a time value specifying the starting point of the segment.
duration
Contains a time value that specifies the duration of the segment.

DESCRIPTION

The GetMediaDataSize function returns a long integer that contains the size, in bytes, of the media's sample data that lies in the specified segment. Note that this number does not necessarily correspond to the amount of sample data used in the track that contains the media. Some samples in the media may not be used in the track, and others may be used more than once.

ERROR CODES

invalidMedia

-2008

This media is corrupted or invalid

invalidDuration

-2014

This duration value is invalid

invalidTime

-2015

This time value is invalid

GetMediaSampleCount

The GetMediaSampleCount function allows you to determine the number of samples in a media.

pascal long GetMediaSampleCount (Media theMedia);
theMedia
Specifies the media for this operation. You obtain this media identifier from such Movie Toolbox functions as NewTrackMedia and GetTrackMedia (described on NewTrackMedia and GetTrackMedia , respectively).

DESCRIPTION

The GetMediaSampleCount function returns a long integer that contains the number of samples in the specified media. Note that this number does not necessarily correspond to the number of samples used in the track that contains the media. Some samples in the media may not be used in the track, and others may be used more than once.

ERROR CODES

invalidMedia

-2008

This media is corrupted or invalid

GetMediaSampleDescriptionCount

The GetMediaSampleDescriptionCount function returns the number of sample descriptions in a media.

pascal long GetMediaSampleDescriptionCount (Media theMedia);
theMedia
Specifies the media for this operation. You obtain this media identifier from such Movie Toolbox functions as NewTrackMedia and GetTrackMedia (described on NewTrackMedia and GetTrackMedia , respectively).

DESCRIPTION

The Movie Toolbox identifies a media's sample descriptions with an index value. Index values always range from 1 to the number of sample descriptions in the media. Sample description indexes provide a convenient way to access each sample description in a media.

The format of sample descriptions differs by media type. Sample descriptions for image data are defined by image description structures, which are discussed in the chapter "Image Compression Manager" in this book. Sample descriptions for sound are defined by sound description structures, which are discussed in "The Sound Description Structure," . Sample descriptions for text are defined by text description structures, which are described in "Text Media Handler Functions" beginning on Text Media Handler Functions .

ERROR CODES

invalidMedia

-2008

This media is corrupted or invalid

SEE ALSO

You can use the value returned by this function to control a loop in which you retrieve each sample description in a media by calling the GetMediaSampleDescription function, which is described in the next section.

GetMediaSampleDescription

The GetMediaSampleDescription function allows you to retrieve a sample description from a media.

pascal void GetMediaSampleDescription (Media theMedia, long index,
                                         SampleDescriptionHandle descH);
theMedia
Specifies the media for this operation. You obtain this media identifier from such Movie Toolbox functions as NewTrackMedia and GetTrackMedia (described on NewTrackMedia and GetTrackMedia , respectively).
index
Specifies the index of the sample description to retrieve. This index corresponds to the sample description itself, not the samples in the media.
descH
Specifies a handle that is to receive the sample description. The Movie Toolbox correctly resizes this handle for the returned sample description. If there is no description for the specified index, the function returns this handle unchanged. Your application must allocate and dispose of this handle.

DESCRIPTION

This function provides a convenient way to retrieve information that describes a sample. For example, you can use this function to retrieve an image media's color lookup table.

The format of sample descriptions differs by media type. Sample descriptions for image data are defined by image description structures, which are discussed in the chapter "Image Compression Manager" in this book. Sample descriptions for sound are defined by sound description structures, which are discussed earlier in this chapter. Sample descriptions for text are defined by text description data structures, which are described in "Text Media Handler Functions," .

The Movie Toolbox identifies a media's sample descriptions with an index value. Index values always range from 1 to the number of sample descriptions in the media. Sample description indexes provide a convenient way to access each sample description in a media.

ERROR CODES

invalidMedia

-2008

This media is corrupted or invalid

badDataRefIndex

-2050

Data reference index value is invalid

Memory Manager errors

SEE ALSO

You can determine the number of sample descriptions in a media by calling the GetMediaSampleDescriptionCount function, which is described in the previous section.

SetMediaSampleDescription

The SetMediaSampleDescription function lets you change the contents of a particular sample description of a specified media.

pascal OSErr SetMediaSampleDescription (Media theMedia,
                                          long index,
                                          SampleDescriptionHandle descH);
theMedia
Specifies the media for this operation. You obtain this media identifier from such Movie Toolbox functions as NewTrackMedia and GetTrackMedia (described on NewTrackMedia and GetTrackMedia , respectively).
index
Specifies the index of the sample description to be changed. This index corresponds to the sample description itself, not the samples in the media. This long integer must be between 1 and the largest sample description index.
descH
Specifies the handle to the sample description. If there is no description for the specified index, the function returns this handle unchanged.

DESCRIPTION

The SetMediaSampleDescription function can be useful in the case of a media handler, such as a text media handler, that stores playback information in its sample description, as opposed to just data format information (as in the case of the video media handler). For more on media handlers, see Inside Macintosh: QuickTime Components .

SPECIAL CONSIDERATIONS

Because a sample description structure may define the format of the data, you should not assume the description describes the data. You should use this function only on an inactive track.

MediaTimeToSampleNum

The MediaTimeToSampleNum function allows you to find the sample that contains the data for a specified time. You indicate the time in the media's time scale.

pascal void MediaTimeToSampleNum (Media theMedia, TimeValue time,
                                         long *sampleNum,
                                         TimeValue *sampleTime,
                                         TimeValue *sampleDuration);
theMedia
Specifies the media for this operation. You obtain this media identifier from such Movie Toolbox functions as NewTrackMedia and GetTrackMedia (described on NewTrackMedia and GetTrackMedia , respectively).
time
Specifies the time for which you are retrieving sample information. You must specify this value in the media's time scale.
sampleNum
Contains a pointer to a long integer that is to receive the sample number. The Movie Toolbox returns the sample number that identifies the sample that contains data for the time specified by the time parameter.
sampleTime
Contains a pointer to a time value. The MediaTimeToSampleNum function updates this time value to indicate the starting time of the sample that contains data for the time specified by the time parameter. This time value is expressed in the media's time scale. Set this parameter to nil if you do not want this information.
sampleDuration
Contains a pointer to a time value. The Movie Toolbox returns the duration of the sample that contains data for the time specified by the time parameter. This time value is expressed in the media's time scale. Set this parameter to nil if you do not want this information.

DESCRIPTION

The Movie Toolbox returns information about the sample that contains data for that time, including its starting time, duration, and sample number.

The MediaTimeToSampleNum function does not account for edits applied to the media by a movie's tracks. If you want to work with edits, use the functions that allow you to look for interesting times. These functions are described in "Finding Interesting Times," beginning on Finding Interesting Times .

ERROR CODES

invalidMedia

-2008

This media is corrupted or invalid

SEE ALSO

You can convert a sample number into a time in a media's time scale by calling the SampleNumToMediaTime function, which is described in the next section.

SampleNumToMediaTime

The SampleNumToMediaTime function allows you to find the time at which a specified sample plays. This time is expressed in the media's time scale.

pascal void SampleNumToMediaTime (Media theMedia,
                                         long logicalSampleNum,
                                         TimeValue *sampleTime,
                                         TimeValue *sampleDuration);
theMedia
Specifies the media for this operation. You obtain this media identifier from such Movie Toolbox functions as NewTrackMedia and GetTrackMedia (described on NewTrackMedia and GetTrackMedia , respectively).
logicalSampleNum
Specifies the sample number.
sampleTime
Contains a pointer to a time value. The MediaTimeToSampleNum function updates this time value to indicate the starting time of the sample specified by the logicalSampleNum parameter. This time value is expressed in the media's time scale. Set this parameter to nil if you do not want this information.
sampleDuration
Contains a pointer to a time value. The Movie Toolbox returns the duration of the sample specified by the logicalSampleNum parameter. This time value is expressed in the media's time scale. Set this parameter to nil if you do not want this information.

ERROR CODES

invalidMedia

-2008

This media is corrupted or invalid

SEE ALSO

You can find the sample for a specified time by calling the MediaTimeToSampleNum function, which is described in the previous section.


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next